//
//  UIBarButtonItem+Extension.swift
//  SinaWeibo
//
//  Created by 韩啸宇 on 15/12/23.
//  Copyright © 2015年 backy. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    convenience init(target: AnyObject?, action: Selector, imageName: String?) {

        let btn = UIButton()

        // 如果传入图片名, 设置图片
        if let imgName = imageName {
            btn.setBackgroundImage(UIImage(named: imgName), forState: UIControlState.Normal)
            btn.setBackgroundImage(UIImage(named: imgName + "_highlighted"), forState: UIControlState.Highlighted)
        }
        // 添加点击事件
        btn.addTarget(target ?? nil, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        
        btn.sizeToFit()

        self.init(customView: btn)
    }
}